package newPan3d.content.ground
{
	import _Pan3D.core.MathCore;
	import _Pan3D.program.Program3DManager;
	
	import _me.Scene_data;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display3D.Context3D;
	import flash.display3D.Program3D;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	import newPan3d.content.ground.groundUp.GroundUpDisplay3DSprite;
	
	import robotleMvc.frameworks.GroundDisplay3DContainer;
	
	import test.vo.StatVO;

	public class GroundLevel
	{
		private var _groundContainer:GroundDisplay3DContainer;
		private var _context3D:Context3D;
		private var _groundItem:Array;
		private var _groundPicBmp:BitmapData;
		
		[Embed(source="../_File/nijia2/ground/loadInfo.jpg")]
		private static var pic:Class;
		
		public function GroundLevel()
		{
			_groundContainer=new GroundDisplay3DContainer();
			_context3D=Scene_data.context3D;
			loadBuildConfigXml();
			
		}
		private function addPicMakeGroundDisplay3D():void
		{
			
			_groundPicBmp=new BitmapData(100,100,false,0x000000);
		//	var kk:BitmapData=Bitmap(new pic()).bitmapData
			_groundPicBmp.draw(Bitmap(new pic()).bitmapData);
			_groundPicBmp.fillRect(new Rectangle(42,42,10,10),0xff0000)
			
			var sprite3D:GroundUpDisplay3DSprite =new GroundUpDisplay3DSprite(_context3D);
			sprite3D.groundPicBmp=_groundPicBmp;
			sprite3D.url ="baseGround_picGround";
			sprite3D.x=0;
			sprite3D.y=-1;
			sprite3D.z=0;
			sprite3D.scale=1;
			_groundContainer.addChild(sprite3D);
			
			var treeShaderProgram3d:Program3D = Program3DManager.getInstance().getProgram(NewGroundShader.NEW_GROUND_SHADER);
			
			_groundContainer.setProgram3D(treeShaderProgram3d);
			
			
		}
		private function loadBuildConfigXml():void
		{
			//加载地面XML列表
			var _loaderURL:URLRequest = new URLRequest(Scene_data.fileRoot+"ground/"+"groundList.xml");
			var _scenexml:URLLoader=new URLLoader();
			_scenexml.load(_loaderURL);
			_scenexml.addEventListener(Event.COMPLETE, _loadGroundXmlOk);
			function _loadGroundXmlOk(event:Event):void
			{  
				//将XML数据传到MODEL进行解析。
				preasXml(XML(_scenexml.data));
			
			}
		}
		private function preasXml(_xml:XML):void
		{
			var _item:Array =MathCore.getSourcePro(_xml);
	
			

           
			var _groundItem:Array=new Array;
			for(var  i:int=0;i<_item.length;i++){
				var statVO:StatVO=new StatVO;
				statVO.et=_item[i].et;
				statVO.scale=_item[i].scale;
				statVO.x=_item[i].x;
				statVO.y=_item[i].y;
				statVO.z=_item[i].z;
				statVO.type=_item[i].type;
				statVO.name=_item[i].name;
				_groundItem.push(statVO);
			}
			for(var j:int=0;j<_groundItem.length;j++){
				var tempVo:StatVO=_groundItem[j] as StatVO;
				var sp1:NewGroundDisplay3DSprite =new NewGroundDisplay3DSprite(_context3D);
				sp1.url =tempVo.et
				sp1.x=tempVo.x
				sp1.y=tempVo.y;
				sp1.z=tempVo.z;
				sp1.scale=tempVo.scale;
				_groundContainer.addChild(sp1);
	
			}
			var treeShaderProgram3d:Program3D = Program3DManager.getInstance().getProgram(NewGroundShader.NEW_GROUND_SHADER);
		
			_groundContainer.setProgram3D(treeShaderProgram3d);
			
			//addPicMakeGroundDisplay3D();

		}
		public function upData():void
		{
			_groundContainer.update();
		
			
		}
	}
}